package leetCode.fourthWeek;

import java.util.LinkedList;
import java.util.List;

public class Code_78 {
  List<List<Integer>> res = new LinkedList<>();

  public List<List<Integer>> subsets(int[] nums) {
    dfs(nums, 0, -1, nums.length, new LinkedList<>());
    return res;
  }

  public void dfs(int[] nums, int index, int root, int k, List<Integer> tmp) {
    if ((index == root && index != 0 && root != 0) || index >= nums.length) {
      return;
    }
    if (!res.contains(tmp)) {
      res.add(new LinkedList<>(tmp));
    }
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        if (tmp.contains(nums[j])) {
          return;
        }
        tmp.add(nums[j]);
        dfs(nums, j, i, k, tmp);
        tmp.remove(tmp.size() - 1);
      }
    }
  }
}
